package com.test;

import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

public class CustomValidator {	
	
    public static boolean isNull(String value){
    	return StringUtils.isNotBlank(value);
    }
	
	public static boolean matchRegexp(String value, String regexp) {
        if (regexp == null || regexp.length() <= 0) {
            return false;
        }
        if (value == null) {
            return false;
        }
        return Pattern.compile(regexp).matcher(value).matches();
    }
	
	public static boolean lengthRange(String value, int min, int max) {
		if(value == null){
			return false;
		}
		if(min == 0 && max == 0){
			return false;
		}
		
		if(min > 0 && max > 0){
			return ( (value.length() >= min) && (value.length() <=max) );
		}else if(min > 0){
			return (value.length() >= min);
		}else{
			return (value.length() <= max);
		}
    }
	
	public static boolean ignore(String value, String mask){
		if(mask == null){
			return true;
		}
		if(mask.equals(value)){
			return false;
		}
		return true;
	}
	
	public static boolean check(String value, String mask){
		if(mask == null){
			return false;
		}
		if(mask.equals(value)){
			return true;
		}
		return false;
	}
	
	public static boolean biggerThan(String submittedValue, String relValue){
		int sv = Integer.parseInt(StringUtils.isBlank(submittedValue)?"0":submittedValue);
		int rv = Integer.parseInt(StringUtils.isBlank(relValue)?"0":relValue);
		return sv>rv;
	}
}
